package com.oocl.producer.output;

import java.io.IOException;
import java.util.Date;
import java.util.Random;

import com.oocl.producer.pojo.Book;
import com.oocl.producer.util.NameUtil;
import com.oocl.producer.util.XMLUtil;

/**
 * 生产随机Book数据
 * @author GANAB
 *
 */
public class BookXmlOutput {
	public BookXmlOutput() {}
	/**
	 * Build book
	 * @param total
	 * @return
	 * @throws IOException 
	 */
	public void output(int total){
		Book book = null;
		
		for(int i = 0; i < total; i++){
			book = new Book();
			book.setAuthor(NameUtil.getRandomName());
			book.setIsNew((new Random().nextInt(2)==1) ? "0" : "1");
			book.setName(NameUtil.getRandomName());
			book.setPrice(new Random().nextDouble() * new Random().nextInt(50));
			book.setPubDate(new Date());
			book.setPublisher("Publisher"+new Random().nextInt(10));
			XMLUtil.outputBookXmlToFile(book);
		}
	}
}
